const submitButtonOptions = {
  wrapperCol: {
    span: 24
  },
  buttonList: [{
    title: '登录',
    block: true,
    col: 18,
    type: 'primary',
    cb: 'submit'
  }]
}
const regFormOptions = {
  wrapperCol: {
    span: 18,
    offset: 3
  },
  labelCol: {
    span: 5
  },
  layout: 'horizontal',
  formConfig: []
}

const loginFormOptions = {
  wrapperCol: {
    span: 18,
    offset: 3
  },
  labelCol: {},
  layout: 'horizontal',
  formConfig: []
}

const FORM_CONFIG_LOGIN = {
  initModel: {
    email: '',
    password: '',
    code: '',
    uuid: ''
  }, // 默认值
  tempModel: {}, // 保存值
  formRootInstance: {
    // 整体表单配置
    ...loginFormOptions,
    baseFormConfig: [{
        type: 'input',
        placeholder: '请输入注册邮箱',
        prop: 'email',
        allowClear: true,
        sloteOptions: [{
          type: 'icon',
          sloteType: 'user',
          position: 'prefix',
          key: '1'
        }]
      },
      {
        type: 'password',
        placeholder: '请输入密码',
        prop: 'password',
        allowClear: true,
        sloteOptions: [{
          type: 'icon',
          sloteType: 'lock',
          position: 'prefix',
          key: '1'
        }]
      },
      {
        type: 'input',
        placeholder: '输入验证码',
        prop: 'code',
        allowClear: true,
        isAuthCode: true
        // sloteOptions: [ //   { //     type: 'icon', sloteType: 'safety-certificate', position: 'prefix', key: '1' //   } // ]
      }
    ]
  },
  rules: {
    email: [{
        required: true,
        message: '邮箱不能为空',
        trigger: ['blur']
      }
      // { required: true, message: '账号填写格式有误', max: 80, pattern: '+A[a-ZA-Z0-9_]+@[a-ZA-Z0-9_-]+(.[a-ZA-Z0-9_-]+)+$', trigger: ['blur'], },
    ],
    password: [{
        required: true,
        message: '密码不能为空',
        trigger: ['blur']
      }
      // { required: true, message: '密码长度必须在6-16之间', min: 6, max: 16, trigger: ['blur'], },
      // { required: true, message: '密码格式有误,含有非法字符[ ;|<>``&!*(~^)#?:"/$=\\"+]', pattern: '[a-z、A-Z、0-9 ]', trigger: ['blur'], },
    ],
    code: [{ 
      required: true,
      message: '验证码不能为空',
      trigger: ['blur']
    }]
  },
  submitButtonOptions
}
// var reg = new RegExp(
//   '^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$'
// ) // 校验手机号

const FORM_CONFIG_REGISTER = {
  // 注册
  initModel: {}, // 默认值
  tempModel: {}, // 保存值
  formRootInstance: {
    // 整体表单配置
    ...regFormOptions,
    baseFormConfig: [{
        type: 'input',
        placeholder: '用户名',
        prop: 'username',
        allowClear: true,
      },
      {
        type: 'password',
        placeholder: '密码',
        prop: 'password',
        allowClear: true,
      },
      {
        type: 'password',
        placeholder: '确认密码',
        prop: 'affirmPassword',
        allowClear: true,
      },
      {
        type: 'input',
        placeholder: '注册邮箱',
        prop: 'email',
        allowClear: true,
      },
      {
        type: 'input',
        placeholder: '输入验证码',
        prop: 'code',
        allowClear: true,
        isAuthCode: true,
      }
    ]
  },

  rules: {
    username: [{
      required: true,
      message: '用户名不能为空',
      trigger: ['blur']
    }],
    email: [{
        type: 'email',
        message: '请输入正确的邮箱!'
      },
      {
        required: true,
        message: '账号不能为空',
        trigger: ['blur']
      }
      // { required: true, message: '账号填写格式有误', max: 80, pattern: '+A[a-ZA-Z0-9_]+@[a-ZA-Z0-9_-]+(.[a-ZA-Z0-9_-]+)+$', trigger: ['blur'], },
    ],
    affirmPassword: [{
        required: true,
        message: '确认密码不能为空',
        trigger: ['blur']
      },
      {
        validator: (rule, value, callback) => {
          if (value === '') {
            callback(new Error('请再次输入新密码'))
          } else {
            callback()
          }
        }
      }
      // { required: true, message: '密码长度必须在6-16之间', min: 6, max: 16, trigger: ['blur'], },
      // { required: true, message: '密码格式有误,含有非法字符[ ;|<>``&!*(~^)#?:"/$=\\"+]', pattern: '[a-z、A-Z、0-9 ]', trigger: ['blur'], },
    ],
    password: [{
        required: true,
        message: '密码不能为空',
        trigger: ['blur']
      },
      {
        pattern: /(?=.*([a-zA-Z].*))(?=.*[0-9].*)[a-zA-Z0-9-*/+.~!@#$%^&*()]{6,20}$/,
        message: '请输入6-20位含有字母、数字或符号！'
      }

      // { required: true, message: '密码长度必须在6-16之间', min: 6, max: 16, trigger: ['blur'], },
      // { required: true, message: '密码格式有误,含有非法字符[ ;|<>``&!*(~^)#?:"/$=\\"+]', pattern: '[a-z、A-Z、0-9 ]', trigger: ['blur'], },
    ],
    code: [{
      required: true,
      message: '验证码不能为空',
      trigger: ['blur']
    }],
    wxRegCode: [{
      required: true,
      message: '注册验证码不能为空',
      trigger: ['blur']
    },
    {
    validator: (rule, value, callback) => {
      if (value !== 'FSIPPC123') {
        callback(new Error('请输入正确注册验证码'))
      } else {
        callback()
      }
    }
  }]
  },
  submitButtonOptions: {
    ...submitButtonOptions,
    buttonList: [{
      title: '注册',
      block: true,
      col: 18,
      type: 'primary',
      cb: 'submit'
    }]
  }
}

const FORM_CONFIG_FORGET = {
  initModel: {}, // 默认值
  tempModel: {}, // 保存值
  formRootInstance: {
    // 整体表单配置
    ...loginFormOptions,
    baseFormConfig: [{
        type: 'input',
        placeholder: '邮箱',
        prop: 'email',
        allowClear: true
      },
      {
        type: 'input',
        placeholder: '输入验证码',
        prop: 'code',
        allowClear: true,
        isAuthCode: true
      }
    ]
  },
  rules: {
    email: [{
      required: true,
      message: '账号不能为空',
      trigger: ['blur']
    }],
    code: [{
      required: true,
      message: '验证码不能为空',
      trigger: ['blur']
    }]
  },
  submitButtonOptions: {
    ...submitButtonOptions,
    buttonList: [{
      title: '找回密码',
      block: true,
      col: 18,
      type: 'primary',
      cb: 'submit'
    }]
  }
}

module.exports = {
  FORM_CONFIG_LOGIN,
  FORM_CONFIG_REGISTER,
  FORM_CONFIG_FORGET
}